package org.serverct.finalfight.game.morerecipes;

import org.bukkit.configuration.file.YamlConfiguration;
import org.serverct.finalfight.FinalFight;
import org.serverct.finalfight.internal.game.morerecipes.*;

import java.io.File;
import java.util.HashMap;

public class RecipeHandler {
    public static HashMap<String, BasicRecipe> recipes = new HashMap<>();

    public static void loadRecipes() {
        File recipeDirectory = new File(FinalFight.plugin.getDataFolder() + "/recipes/");
        if (!recipeDirectory.exists()) {
            FinalFight.plugin.saveResource("recipes/", false);
        }
        for (File file : recipeDirectory.listFiles()) {
            YamlConfiguration yaml = YamlConfiguration.loadConfiguration(file);

            String name = file.getName().replace(".yml", "");
            RecipeType type = RecipeType.valueOf(yaml.getString("type"));

            switch (type) {
                case SMELT:
                    recipes.put(name, new SmeltingRecipe(yaml));
                    break;
                case SDC:
                    recipes.put(name, new SDCraftingRecipe(yaml));
                    break;
                case SLC:
                    recipes.put(name, new SLCraftingRecipe(yaml));
                    break;
            }
        }
    }
}
